package com.zrf.base.knowledge.guava;

import com.google.common.base.Optional;

/**
 * @author zhouruifeng
 *         Created by zhouruifeng on 2017/7/12.
 */
public class OptionalTest {
    public static void main(String[] args) {
        Optional<Integer> possible = Optional.of(5);
        System.out.println(possible.isPresent());
        System.out.println(possible.get());

//        possible = Optional.of(null);//java.lang.NullPointerException

        possible = Optional.absent();
        System.out.println(possible.isPresent());
//        System.out.println(possible.get());//java.lang.IllegalStateException: Optional.get() cannot be called on an absent value

        possible = Optional.fromNullable(null);
        System.out.println(possible.or(0));
    }
}
